home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / gfx / x11 / oldXlib.lha / oldXlib / src / lib / oldX / XCrAssoc.c < prev    next >
C/C++ Source or Header  |  1994-04-18  |  3KB  |  74 lines

  1. /* $XConsortium: XCrAssoc.c,v 10.18 94/04/17 20:11:34 rws Exp $ */
  2. /*
  3.  
  4. Copyright (c) 1985  X Consortium
  5.  
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12.  
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15.  
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
  19. X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  20. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.  
  23. Except as contained in this notice, the name of the X Consortium shall not be
  24. used in advertising or otherwise to promote the sale, use or other dealings
  25. in this Software without prior written authorization from the X Consortium.
  26.  
  27. */
  28.  
  29. #include "Xlibint.h"
  30. #include "X10.h"
  31.  
  32. /*
  33.  * XCreateAssocTable - Create an XAssocTable.  The size argument should be
  34.  * a power of two for efficiency reasons.  Some size suggestions: use 32
  35.  * buckets per 100 objects;  a reasonable maximum number of object per
  36.  * buckets is 8.  If there is an error creating the XAssocTable, a NULL
  37.  * pointer is returned.
  38.  */
  39. XAssocTable *XCreateAssocTable(size)
  40.     register int size;        /* Desired size of the table. */
  41. {
  42.     register XAssocTable *table;    /* XAssocTable to be initialized. */
  43.     register XAssoc *buckets;    /* Pointer to the first bucket in */
  44.                     /* the bucket array. */
  45.     
  46.     /* XMalloc the XAssocTable. */
  47.     if ((table = (XAssocTable *)Xmalloc(sizeof(XAssocTable))) == NULL) {
  48.         /* XMalloc call failed! */
  49.         errno = ENOMEM;
  50.         return(NULL);
  51.     }
  52.     
  53.     /* XMalloc the buckets (actually just their headers). */
  54.     buckets = (XAssoc *)Xcalloc((unsigned)size, (unsigned)sizeof(XAssoc));
  55.     if (buckets == NULL) {
  56.         /* XCalloc call failed! */
  57.         errno = ENOMEM;
  58.         return(NULL);
  59.     }
  60.  
  61.     /* Insert table data into the XAssocTable structure. */
  62.     table->buckets = buckets;
  63.     table->size = size;
  64.  
  65.     while (--size >= 0) {
  66.         /* Initialize each bucket. */
  67.         buckets->prev = buckets;
  68.         buckets->next = buckets;
  69.         buckets++;
  70.     }
  71.  
  72.     return(table);
  73. }
  74.